package VacationTest.PlaneFight.src;

import javax.swing.*;
import java.awt.*;

public class HeroPlane extends Thread implements Direction{

    int x = 230, y = 650;
    int width = 50, height = 50;
    int speed = 8;
    Image img = new ImageIcon(
            "E:\\JavaCode\\AirWar\\src\\VacationTest\\PlaneFight\\Image\\HeroPlane.png")
            .getImage();

    // 两种 构造器
    public HeroPlane() {

    }

    public HeroPlane(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
    // 定义方向键标志 up down left right
    private boolean up, down, left, right;
    public void run() {
        while (true) {
            // 实现 英雄机的 移动
            if (up) {
                if (y > 20) {
                    y -= speed;
                } else {
                    y -= 0;
                }
            }
            if (down) {
                if (y < 700)
                    y += speed;
                else
                    y += 0;
            }
            if (left) {
                if (x > 10)
                    x -= speed;
                else
                    x -= 0;
            }
            if (right) {
                if (x < 440)
                    x += speed;
                else
                    x += 0;
            }
            try {
                Thread.sleep(10);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }

        }

    }

    public void setDirection(String str, boolean b) {
        switch (str) {
            case "up" -> up = b;
            case "down" -> down = b;
            case "left" -> left = b;
            case "right" -> right = b;
            default -> throw new IllegalStateException("Unexpected value: " + str);
        }
    }
}


